package by.alex.dzeshko.lastfmsimple.content.provider;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.net.Uri;
import android.text.TextUtils;
import by.alex.dzeshko.lastfmsimple.bo.AlbumModel;
import by.alex.dzeshko.lastfmsimple.content.Contract;
import by.alex.dzeshko.lastfmsimple.content.provider.common.CommonProvider;
import by.alex.dzeshko.lastfmsimple.utils.Md5;

public class AlbumsProvider extends CommonProvider{

	@Override
	protected String getOrderBy() {
		return null;
	}

	@Override
	protected String getTableName() {
		return Contract.AlbumsColumns.TABLE_NAME;
	}

	@Override
	protected String getContentType() {
		return Contract.AlbumsColumns.CONTENT_TYPE;
	}

	@Override
	protected Uri getContentURI() {
		return Contract.AlbumsColumns.CONTENT_URI;
	}

	@Override
	protected String[] getColumns() {
		return Contract.AlbumsColumns.COLUMNS;
	}

	@Override
	protected ContentValues getContentValues(JSONObject jsonObject)
			throws JSONException {
		ContentValues values = new ContentValues();
		AlbumModel album = new AlbumModel(jsonObject);
		String mbid = album.getMbid();
		String name = album.getName();
		if(TextUtils.isEmpty(mbid)){
			mbid = Md5.convert(name);
		}
		values.put(Contract.AlbumsColumns.MBID, mbid);
		values.put(Contract.AlbumsColumns.NAME, name);
		values.put(Contract.AlbumsColumns.ARTIST, album.getArtist());
		values.put(Contract.AlbumsColumns.URL, album.getUrl());
		values.put(Contract.AlbumsColumns.IMAGE_SMALL, album.getImage(0));
		values.put(Contract.AlbumsColumns.IMAGE_MEDIUM, album.getImage(1));
		values.put(Contract.AlbumsColumns.IMAGE_LARGE, album.getImage(2));
		values.put(Contract.AlbumsColumns.IMAGE_XLARGE, album.getImage(3));
		values.put(Contract.AlbumsColumns.MARKER, album.getMarker());
		return values;
	}

}
